<!--
@description ：敏感词详情
-->

<template>
  <div>
    <el-card>
      <div style="display: flex;justify-content: space-between;align-items: center">
        <h3 style="display: inline-block">敏感词详情</h3>
        <el-button plain type="info" @click="goback">返回</el-button>
      </div>
    </el-card>
    <div class="data-textarea">
      <div class="data-card" style="margin-left: 0">
        <div class="data-info">
          <div>
            <svg-icon icon-class="sensitive01" style="font-size: 26px;margin-right: 14px"></svg-icon>
            今日敏感词触发次数
          </div>
          <el-tooltip content="员工今日触发敏感词次数" effect="dark" placement="top">
            <svg-icon icon-class="question-white"></svg-icon>
          </el-tooltip>
        </div>
        <div class="data-num">
          {{ wordCount.todayWordNum || 0 }}
        </div>
      </div>
      <div class="data-card" style="margin-left: 0">
        <div class="data-info">
          <div>
            <svg-icon icon-class="sensitive02" style="font-size: 26px;margin-right: 14px"></svg-icon>
            今日触发敏感词员工数
          </div>
          <el-tooltip content="今日触发敏感词员工数" effect="dark" placement="top">
            <svg-icon icon-class="question-white"></svg-icon>
          </el-tooltip>
        </div>
        <div class="data-num">
          {{ wordCount.todayUserNum || 0 }}
        </div>
      </div>
      <div class="data-card" style="margin-left: 0">
        <div class="data-info">
          <div>
            <svg-icon icon-class="sensitive03" style="font-size: 26px;margin-right: 14px"></svg-icon>
            敏感词触发总次数
          </div>
          <el-tooltip content="员工历史触发敏感词触发总次数" effect="dark" placement="top">
            <svg-icon icon-class="question-white"></svg-icon>
          </el-tooltip>
        </div>
        <div class="data-num">
          {{ wordCount.wordNum || 0 }}
        </div>
      </div>
      <div class="data-card" style="margin-left: 0">
        <div class="data-info">
          <div>
            <svg-icon icon-class="sensitive04" style="font-size: 26px;margin-right: 14px"></svg-icon>
            触发敏感词员工总数
          </div>
          <el-tooltip content="历史触发敏感词员工总数" effect="dark" placement="top">
            <svg-icon icon-class="question-white"></svg-icon>
          </el-tooltip>
        </div>
        <div class="data-num">
          {{ wordCount.userNum || 0 }}
        </div>
      </div>
    </div>
    <el-card class="wrap g-card" style="padding: 0">
      <div class="title-header">基础信息</div>
      <div class="wrap-info">
        <div class="info-item">
          <div class="info-item-q">创建人</div>
          <div class="info-item-a">{{ wordDetail.createBy }}</div>
        </div>
        <div class="info-item">
          <div class="info-item-q">更新时间</div>
          <div class="info-item-a">{{ wordDetail.updateTime }}</div>
        </div>
        <div class="info-item">
          <div class="info-item-q">敏感词</div>
          <div v-if="wordDetail.sensitiveWord" class="info-item-a">
            <el-tag
              v-for="(tag,index) in wordDetail.sensitiveWord.split(',')"
              :key="index"
              :disable-transitions="false">
              {{ tag }}
            </el-tag>
          </div>
        </div>
        <div class="info-item">
          <div class="info-item-q">是否启用触发撤回</div>
          <div class="info-item-a">{{ wordDetail.isRevocation == '0' ? '是' : '否' }}</div>
        </div>
      </div>
    </el-card>
    <el-card>
      <el-form :model="queryForm" style="display: flex;margin: 12px 0 0 12px">
        <el-form-item prop="weUserId">
          <el-select v-model="queryForm.weUserIdList" clearable multiple
                     placeholder="触发员工" style="width: 200px;" @change="handleQuery">
            <el-option
              v-for="(item, index) in weUserIdList"
              :key="index"
              :label="item.weUserName"
              :value="item.weUserId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="dateRange">
          <el-date-picker v-model="queryForm.dateRange" align="right" clearable end-placeholder="结束日期"
                          range-separator="至" start-placeholder="开始日期" type="daterange" @change="setChange"></el-date-picker>
        </el-form-item>
        <el-form-item prop="handleStatus">
          <el-select v-model="queryForm.handleStatus" clearable placeholder="处理状态"
                     style="width: 200px;" @change="handleQuery">
            <el-option
              v-for="item in handleStatusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="handleResult">
          <el-select v-model="queryForm.handleResult" clearable placeholder="处理结果"
                     style="width: 200px;" @change="handleQuery">
            <el-option
              v-for="item in handleResultList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="isSuccess">
          <el-select v-model="queryForm.isSuccess" clearable placeholder="是否撤回成功"
                     style="width: 200px;" @change="handleQuery">
            <el-option
              v-for="item in isSuccessList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="tableList" max-height="560" min-height="420"
                style="width: calc(100% - 24px);margin: 12px 24px;">
        <el-table-column :show-overflow-tooltip="true" align="center" label="触发员工" min-width="140"
                         prop="weUserName"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="center" label="聊天客户" min-width="140"
                         prop="wechatNickname">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" align="center" label="发送原文" min-width="200"
                         prop="content">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="触发敏感词" min-width="160"
                         prop="sensitiveWord">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="触发时间" min-width="170"
                         prop="triggerTime">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="是否撤回成功" min-width="140"
                         prop="isSuccess">
          <template slot-scope="scope">
                  <span :style="scope.row.isSuccess == 0 ? 'color:#14D595' : 'color: #082AFF'">{{
                      scope.row.isSuccessName
                    }}</span>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="处理状态" min-width="120"
                         prop="handleStatusName">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="处理人" min-width="140"
                         prop="handleUser">
        </el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="处理时间" min-width="170"
                         prop="handleTime"></el-table-column>
        <el-table-column :show-overflow-tooltip="false" align="center" label="处理结果" min-width="150"
                         prop="handleResult">
          <template slot-scope="scope">
            <span style="margin-right: 12px">{{ scope.row.handleResultName }}</span>
            <div style="display: inline-block" v-if="scope.row.handleStatus == '1' && scope.row.remark">
              <el-tooltip :content="scope.row.remark" effect="dark" placement="top">
                <span>备注</span>
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作"
                         width="140">
          <template slot-scope="{ row }">
            <div style="display: flex; justify-content: space-around">
              <el-button size="mini" type="text" @click="toDispose(row)" :disabled="row.handleStatus == 1" :style="`color: ${ row.handleStatus == 1 ? '#cccccc' : '#082AFF' }`">处理
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <NormalPagination :currentPage="queryForm.pageNum" :page-size-list="pageSizeList" :pageSize="queryForm.pageSize"
                        :total="total" @handleCurrentChange="handleCurrentChange"
                        @handleSizeChange="handlePageSizeChange"></NormalPagination>
    </el-card>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :show-close="true"
               :visible.sync="disposeVisible"
               title="处理操作" width="520px">
      <el-form ref="disposeForm" :model="disposeForm" :rules="rules" label-width="120px">
        <el-form-item label="处理结果" prop="handleResult">
          <el-radio-group v-model="disposeForm.handleResult">
            <el-radio label="0">合规</el-radio>
            <el-radio label="1">违规</el-radio>
            <el-radio label="2">忽略</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="disposeForm.remark" clearable maxlength="200" rows="4" show-word-limit
                    type="textarea"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="cancelCheck" :loading="saveLoading">取 消</el-button>
        <el-button :loading="saveLoading" type="primary" @click="saveCheck">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import * as $api from '@/api/riskManager/word'

export default {
  name: "sensitiveWordMonitoringDetail", //页面名称，必填
  props: {},
  components: {},
  data() {
    return {
      wordCount: {
        todayWordNum: 0,
        todayUserNum: 0,
        wordNum: 0,
        userNum: 0,
      },
      wordDetail: {},
      queryForm: {
        weUserIdList: [],
        dataRange: [],
        triggerStartTime: '',
        triggerEndTime: '',
        handleStatus: null,
        handleResult: null,
        isSuccess: null,
        pageNum: 1,
        pageSize: 10,
      },
      pageSizeList: [10, 20, 30, 50],
      weUserIdList: [],
      handleStatusList: [
        {dictValue: '0', dictLabel: '未处理'},
        {dictValue: '1', dictLabel: '已处理'},
      ],
      handleResultList: [
        {dictValue: '0', dictLabel: '合规'},
        {dictValue: '1', dictLabel: '违规'},
        {dictValue: '2', dictLabel: '忽略'},
      ],
      isSuccessList: [
        {dictValue: '0', dictLabel: '成功'},
        {dictValue: '1', dictLabel: '失败'},
      ],

      tableList: [],
      total: 0,
      loading: false,

      disposeVisible: false,
      disposeForm: {
        handleResult: '',
        remark: '',
      },
      triggerRecordId: '',
      rules: {
        handleResult: [{required: true, message: '请选择处理结果', trigger: 'change'}],
      },
      saveLoading: false,

      wordId: '',
    }
  },
  watch: {},
  methods: {
    // 返回按钮
    goback() {
      this.$router.go(-1)
    },
    // 获取统计次数
    getWordCount() {
      $api.getWordCount({wordId: this.wordId || this.$route.query.wordId}).then(res => {
        if (res.code == 200) {
          this.wordCount = {
            ...res.data
          }
        }
      })
    },
    getDetail() {
      $api.querySensitiveWord({wordId: this.wordId || this.$route.query.wordId}).then(res => {
        if (res.code == 200) {
          this.wordDetail = {
            ...res.data
          }
        }
      })
    },
    setChange(e) {
      if (e) {
        this.queryForm.triggerStartTime = e[0]
        this.queryForm.triggerEndTime = e[1]
      } else {
        this.queryForm.triggerStartTime = ''
        this.queryForm.triggerEndTime = ''
      }
      this.handleQuery()
    },
    handleQuery() {
      this.queryForm.pageNum = 1
      this.getListFn()
    },
    handleReset() {

    },
    getListFn() {
      console.log('this.queryForm:::::::::', this.queryForm.handleResult)
      const this_ = this
      let obj = {
        ...this.queryForm,
        wordId: this.wordId || this.$route.query.wordId
      }
      this_.loading = true
      this.tableList = []
      $api.getTriggerRecordList(obj).then(res => {
        if(res.code == 200){
          this_.tableList = res?.rows
          this_.total = res?.total
        }
        this_.loading = false
      }).catch(() => {
        this_.loading = false
      })
    },
    handleCurrentChange(val) {
      this.queryForm.pageNum = val
      this.getListFn()
    },
    handlePageSizeChange(val) {
      this.queryForm.pageNum = 1
      this.queryForm.pageSize = val
      this.getListFn()
    },
    // 处理
    toDispose(row) {
      if(row.handleStatus == 1) return
      this.disposeVisible = true
      this.triggerRecordId = row.triggerRecordId
      this.disposeForm = {
        handleResult: '',
        remark: '',
      }
      this.$nextTick(() => {
        this.$refs['disposeForm'].clearValidate()
      })
    },
    cancelCheck() {
      this.disposeVisible = false
    },
    saveCheck() {
      let obj = {
        triggerRecordId: this.triggerRecordId,
        ...this.disposeForm
      }
      this.$refs.disposeForm.validate(valid => {
        if(valid){
          $api.handleDispose(obj).then(res => {
            if(res.code == 200){
              this.disposeVisible = false
              this.$message.success('处理成功')
              this.handleQuery()
            }
            this.saveLoading = false
          }).catch(() => {
            this.saveLoading = false
          })
        }
      })
    },
  },
  mounted() {
    this.wordId = this.$route.query.wordId
    $api.getTriggerUserList({wordId: this.wordId || this.$route.query.wordId }).then(res => {
      if(res.code == 200){
        this.weUserIdList = res.data
      }
    })
    this.getWordCount()
    this.getDetail()
    this.handleQuery()
  },
  created() {
  },
}

</script>

<style lang="scss" scoped>
@import "../../../../styles/base.scss";

.app-container {
  height: 100%;
}

.data-textarea {
  display: flex;

  .data-card {
    flex: 1;
    background-color: #fff;
    border-radius: 8px;
    margin: 20px 10px 10px;
    //height: 100px;
    padding: 16px 12px 12px 36px;
  }
}

.data-info {
  display: flex;
  justify-content: space-between;
  padding-bottom: 20px;
  font-size: 14px;
  align-items: center;
  color: #505050;
}

.data-num {
  font-size: 36px;
  font-weight: 500;
  padding-bottom: 10px;
}


.wrap {
  @include titleWrap;
}


::v-deep {
  .el-tag {
    margin: 0 0 6px 10px;
    height: 30px;
    color: #999 !important;
    line-height: 30px;
    border: 1px solid #ccc !important;
    border-radius: 3px;
    background: rgba(153, 153, 153, 0.1) !important;
  }
}

.wrap-info {
  padding: 6px 20px 0 38px;

  .info-item {
    line-height: 30px;
    padding: 0 0 12px;
    display: flex;
    color: #505050;

    .info-item-q {
      width: 150px;
    }
  }
}

.g-card {
  ::v-deep.el-card__body {
    padding: 0;
  }
}
</style>
